#define _USE_MATH_DEFINES

#include <iostream>
#include <fstream>
#include <datatable.h>
#include <bspline.h>
#include <bsplinebuilder.h>
#include <nlohmann/json.hpp>
#include <vector>
#include <cmath>

#include "helper.h"

#include "sampler1.h"

using namespace SPLINTER;

int main(int argc, char *argv[])
{
    Sampler1 sampler(1);
    double start = -5, end = 5;
    int Ns[] = {10, 11};
    std::vector<BSpline> splines;
    int degrees[] = {2, 3};
    for (int i = 0; i < len(degrees); i++)
    {
        auto N = Ns[i];
        int degree = degrees[i];
        DataTable samples_table;

        for (int j = 0; j < N; j++)
        {
            DenseVector x(1);
            x(0) = start + (end - start) * j / (N - 1);
            double y = sampler(x)[0];
            samples_table.addSample(x, y);
        }
        BSpline bspline = BSpline::Builder(samples_table).degree(degree).build();

        splines.push_back(bspline);
        plotSpline(bspline, start, end, {{"label", "type=" + std::string((degree == 2) ? "quadratic" : "cubic")}});
    }
    show();

    return 0;
}
